package com.sjy.framework;

import com.sjy.framework.codemultiplex.ScriptTypeEnum;
import groovy.lang.Binding;

import javax.script.SimpleBindings;
import java.util.Map;

public class BindEntityBuilder {

    public static Object buildParam(Map<String,Object> params,String scriptType){
        if(ScriptTypeEnum.GROOVY.getCode().equals(scriptType)){
            Binding binding = new Binding();
            if(params==null ||params.size()==0){return binding;}
            for(Map.Entry<String,Object> entry:params.entrySet()){
                binding.setProperty(entry.getKey(),entry.getValue());
            }
            return binding;
        }else if(ScriptTypeEnum.JAVASCRIPT.getCode().equals(scriptType)){
            SimpleBindings bindings = new SimpleBindings();
            if(params==null ||params.size()==0){return bindings;}
            for(Map.Entry<String,Object> entry:params.entrySet()){
                bindings.put(entry.getKey(),entry.getValue());
            }
            return bindings;
        }
        return null;
    }
}
